package com.numberone.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.numberone.system.mapper.GoodsCollectMapper;
import com.numberone.system.domain.GoodsCollect;
import com.numberone.system.service.IGoodsCollectService;
import com.numberone.common.support.Convert;

/**
 * 商品收藏 服务层实现
 * 
 * @author numberone
 * @date 2020-10-10
 */
@Service
public class GoodsCollectServiceImpl implements IGoodsCollectService 
{
	@Autowired
	private GoodsCollectMapper goodsCollectMapper;

	/**
     * 查询商品收藏信息
     * 
     * @param id 商品收藏ID
     * @return 商品收藏信息
     */
    @Override
	public GoodsCollect selectGoodsCollectById(Long id)
	{
	    return goodsCollectMapper.selectGoodsCollectById(id);
	}
	
	/**
     * 查询商品收藏列表
     * 
     * @param goodsCollect 商品收藏信息
     * @return 商品收藏集合
     */
	@Override
	public List<GoodsCollect> selectGoodsCollectList(GoodsCollect goodsCollect)
	{
		System.out.println(goodsCollect.getUserId()+"======");
	    return goodsCollectMapper.selectGoodsCollectList(goodsCollect);
	}
	
    /**
     * 新增商品收藏
     * 
     * @param goodsCollect 商品收藏信息
     * @return 结果
     */
	@Override
	public int insertGoodsCollect(GoodsCollect goodsCollect)
	{
		List<GoodsCollect> goodsCollects = goodsCollectMapper.selectGoodsCollectList(goodsCollect);
		if (goodsCollects.size() > 0)
		{
			return 0;
		}
		return goodsCollectMapper.insertGoodsCollect(goodsCollect);
	}
	
	/**
     * 修改商品收藏
     * 
     * @param goodsCollect 商品收藏信息
     * @return 结果
     */
	@Override
	public int updateGoodsCollect(GoodsCollect goodsCollect)
	{
	    return goodsCollectMapper.updateGoodsCollect(goodsCollect);
	}

	@Override
	public int deleteGoodsCollectById(Long id) {
		return goodsCollectMapper.deleteGoodsCollectById(id);
	}

	/**
     * 删除商品收藏对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteGoodsCollectByIds(String ids)
	{
		return goodsCollectMapper.deleteGoodsCollectByIds(Convert.toStrArray(ids));
	}

	@Override
	public List<GoodsCollect> selectGoodsCollectListByStatus(Long userId, Integer status) {
		return goodsCollectMapper.selectGoodsCollectListByStatus(userId, status);
	}

	/**
	 * 判断是否收藏
	 * @param userId
	 * @param goodsId
	 * @return
	 */
	@Override
	public Boolean isCollect(Long userId, Long goodsId) {
		int collect = goodsCollectMapper.isCollect(userId, goodsId);
		if (collect > 0)
		{
			return true;
		}
		return false;
	}

	/**
	 * 根据关键字搜索
	 * @param keyword
	 * @return
	 */
	@Override
	public List<GoodsCollect> selectByKeyWord(Long userId, String keyword) {
		return goodsCollectMapper.selectByKeyWord(userId,keyword);
	}

}
